$import( "SmitearWebGL.Objects.Parser.Collada.DaeEntity" );
$import( "SmitearWebGL.Objects.Parser.Collada.DaeBindMaterial" );

SmitearWebGL.Objects.Parser.Collada.DaeInstanceController = SmitearWebGL.Objects.Parser.Collada.DaeEntity.extend(
{
	/******** constructor ********/

	init : function( document, node )
	{
		this.url = "";
		this.skeleton = "";
		this.skeletons = null;
		this.bindMaterial = null;

		this._super( document, node );
		this._registClass( "SmitearWebGL.Objects.Parser.Collada.DaeInstanceController" );
	}
	,
	destroy : function()
	{
		this._super();

		if(this.bindMaterial)
		{
			this.bindMaterial.destroy();
			this.bindMaterial = null;
		}

		this.skeletons = null;
		this.skeleton = null;
	}
	,
	read : function( node )
	{
		this._super( node );

		this.url = this.getAttribute( node, SmitearWebGL.Objects.Parser.Collada.Const.DAE_URL_ATTRIBUTE );

		$LOG( " => " + this.url );

		this.skeleton = null;
		this.skeletons = [];

		var children = node.childNodes;
		var nodeID;

		for( var i = 0; i < children.length; i++ )
		{
			var child = children[i];

			switch( child.localName )
			{
				case SmitearWebGL.Objects.Parser.Collada.Const.DAE_SKELETON_ELEMENT:
					nodeID = this.getNodeContent( child );
					nodeID = nodeID.indexOf("#") != -1 ? nodeID.substr(1) : nodeID;
					this.skeletons.push( nodeID );
					if( !this.skeleton )
					this.skeleton = nodeID;
					$LOG( " => skeleton: " + nodeID );
					break;

				case SmitearWebGL.Objects.Parser.Collada.Const.DAE_BINDMATERIAL_ELEMENT:
					this.bindMaterial = new SmitearWebGL.Objects.Parser.Collada.DaeBindMaterial( this.document, child );
					break;

				case SmitearWebGL.Objects.Parser.Collada.Const.DAE_EXTRA_ELEMENT:
					break;

				default:
					break;
			}
		}
	}
}
);